package com.example.api.controller;

import com.example.api.aspect.SystemControllerLog;
import com.example.api.model.entity.Warehouse;
import com.example.api.model.enums.ActionTypeEnum;
import com.example.api.model.support.RespBean;
import com.example.api.service.WarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "仓库管理")
@RestController
@RequestMapping("/api/warehouse")
public class WarehouseController {

    @Resource
    private WarehouseService warehouseService;

    @ApiOperation("添加仓库")
    @PostMapping("/")
    @SystemControllerLog(description = "添加仓库", actionType = ActionTypeEnum.CREATE)
    public RespBean save(@RequestBody Warehouse warehouse) {
        return warehouseService.save(warehouse);
    }

    @ApiOperation("查询仓库")
    @GetMapping("/")
    @SystemControllerLog(description = "查询仓库", actionType = ActionTypeEnum.QUERY)
    public List<Warehouse> findAll() {
        return warehouseService.findAll();
    }

    @ApiOperation("删除仓库")
    @DeleteMapping("/{id}")
    @SystemControllerLog(description = "删除仓库", actionType = ActionTypeEnum.DELETE)
    public RespBean delete(@PathVariable Integer id) {
        return warehouseService.delete(id);
    }

}
